<%@page import="debugs.SiteConfigDebug"%>
<%@page import="systems.ConfigSystem"%>
<%@page import="entities.SiteConfig"%>
<%@page import="helpers.StringHelper"%>
<%@page import="helpers.DateHelper"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="entities.Category"%>
<%@page import="entities.User"%>
<%@page import="java.util.Map"%>
<%@page import="entities.Article"%>
<%@page import="java.util.List"%>
<%
SiteConfig siteConfig = ConfigSystem.getConfigs();
List<Article> articles = (List<Article>) request.getAttribute("articles");
Map<String, User> authors = (Map<String, User>) request.getAttribute("authors");
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories");
User author = null;
Category category = null;

//Paginator
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/templates/classic/layouts/header.jsp"/>

		<div id="wrapper">
			<div class="row-fluid">
				<div class="span8 left-content">
					<% 
	                for (int i = 0; i < articles.size(); i++) {
	                	category = categories.get(articles.get(i).getCategory());
	                	author = authors.get(articles.get(i).getCreator());
	                %>
					<article>
						<div class="date-info">
							<span class="day"><%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "dd") %></span>
							<span class="month-year"><%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "MMM, yyyy") %></span>
						</div>
						<div class="article-info">
							<div class="article-title">
								<h2><a href="/article/<%=articles.get(i).getAlias() %>"><%=articles.get(i).getTitle() %></a></h2>
							</div>
						</div>
						<div class="article-meta">
							<span><i class="icon-user"></i> 
								<% if (author != null) { %>
		                        &nbsp;<a href="/author/<%=author.getId()%>" itemprop="author"><%=author.getName() %></a> | 
		                        <% } else { %>
		                        &nbsp;<%=articles.get(i).getAuthorName() %> | 
		                        <% } %>
							</span> 
							<span><i class="icon-folder-open"></i> <a href="/category/<%=category.getAlias() %>"><%=category.getName() %></a></span>
							<span class="pull-right">
								<a class="article-entry" href="/article/<%=articles.get(i).getAlias() %>">Read More...</a>
							</span>
						</div>
						<div class="article-desc">
							<p>
								<%=StringHelper.cutString(StringHelper.html2text(articles.get(i).getContent()), 40) %>...
							</p>
						</div>
						
					</article>
					<% } %>
					
					<div class="pagination">
						<%
						List<Integer> range = paginator.getRangePage();
						%>
	                    <% if (prevPage) { %>
						<a href="<%=paginator.getPrev()%>" class="prev page-numbers">Prev</a>
						<% } %>
						<%
						if (nextPage || prevPage) {
							for (int i = 0; i < range.size(); i++) {
								if (range.get(i).intValue() == pages) {
						%>
						<span class="page-numbers current"> <%=range.get(i).toString() %></span>
							<%  } else { %>
						<a class="page-numbers" href="<%=paginator.getPage(range.get(i).intValue())%>"> <%=range.get(i).toString() %></a>
						<%  	}
							}
						} %>
						
						<% if (nextPage) { %>
						<a href="<%=paginator.getNext()%>" class="next page-numbers">Next</a></li>
						<% } %>
					</div>
					
				</div>
				
				<jsp:include page="/templates/classic/elements/right.jsp" />
				
			</div>
		</div>
	
<jsp:include page="/templates/classic/layouts/footer.jsp" />